var api = require('../../config/api.js');
var util = require('../../utils/util.js');
var user = require('../../utils/user.js');

const app = getApp();

// pages/ shipped/ shipped.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shop: {},
    shuzu: []
  },



  getzt() {
    var bg = []
    let that = this
    util.request(api.ShowOrderInfo + "/4", {}, 'get', {
      "x-merchant-request-code": wx.getStorageSync("code"),
      'token': wx.getStorageSync('token')
    }).then(function(res) {
      // console.log("sadsadad")
      var bb = res.data.info
      var arr = Object.keys(bb);
      // console.log(arr.length);  //3
      console.log(bb)

      for (var n = 0; n < arr.length;) {
        for (var i in bb) {

          // console.log(i)          //获得对象中键值对的“键”
          // console.log(bb[i])  //获得对象中键值对的“值”
          var j = bb[i]
          i = i.slice(1, i.length - 1)
          // console.log("kl"+i)

          bg[n] = i.split(",")
          bg[n].push(j)
          n++
        }

      }
      console.log(bg)
      that.setData({
        shuzu: bg
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log("1111" + app.globalData.info)
    this.setData({
      ind: app.globalData.ind,
      shop: app.globalData.ind
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {


    user.checkLogin().then(res => {
      this.getzt()
    }).catch(() => {
      wx.clearStorageSync("token")
      wx.showModal({
        title: '温馨提示',
        content: '登录过期或未登录',
        showCancel: false,
        success: res => {
          wx.redirectTo({
            url: '/pages/login/login',
          })
        }
      })
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})